<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:s="http://jboss.org/seam/faces"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xml:lang="en" lang="en">

<ui:composition template="/resources/layout.xhtml">
    <ui:define name="title" >Заниматели</ui:define>
    <ui:define name="content">
        <h:form id="allDebtorsForm">

            <table>
                <tr>
                    <td>
                        <rich:panel styleClass="fake-app">
                            <a4j:commandButton value="Добавление"
                                               oncomplete="#{rich:component('popupAddDebtor')}.show()"
                                               render="addNewDebtorPanel,addDebtorHeader"
                                               />
                            <rich:tooltip >
                                Добавление нового занимателя
                            </rich:tooltip>
                        </rich:panel>
                    </td>
                </tr>
            </table>

            <rich:dataTable id="allDebtors" value="#{debtorAction.allDebtors}" var="debtor" rows="#{debtorAction.rows}">
                <rich:column sortBy="#{debtor.lastName}"
                             sortOrder="#{debtorAction.debtorListSort.lastNameOrder}"
                             filterValue="#{debtorAction.debtorListFilter.lastNameFilter}"
                             filterExpression="#{fn:containsIgnoreCase(debtor.lastName,debtorAction.debtorListFilter.lastNameFilter)}"
                        >
                    <f:facet name="header">
                        <a4j:commandLink value="Фамилия"
                                         render="allDebtors"
                                         action="#{debtorAction.debtorListSort.sortByLastName}"
                                         styleClass="fake-app"
                                          />
                        <h:inputText id="lastNameFilterInput" value="#{debtorAction.debtorListFilter.lastNameFilter}"
                                     onfocus="var val=this.value; this.value=''; this.value= val;">
                            <a4j:ajax event="keyup"  render="allDebtors" execute="@this" oncomplete="#{rich:element('lastNameFilterInput')}.focus()"/>
                        </h:inputText>
                    </f:facet>
                    <h:outputText value="#{debtor.lastName}" />
                </rich:column>

                <rich:column sortBy="#{debtor.firstName}"
                             sortOrder="#{debtorAction.debtorListSort.firstNameOrder}"
                             filterValue="#{debtorAction.debtorListFilter.firstNameFilter}"
                             filterExpression="#{fn:containsIgnoreCase(debtor.firstName,debtorAction.debtorListFilter.firstNameFilter)}"
                        >
                    <f:facet name="header">
                        <a4j:commandLink value="Имя"
                                         render="allDebtors"
                                         action="#{debtorAction.debtorListSort.sortByFirstName}"
                                         styleClass="fake-app"
                                />
                        <h:inputText id="firstNameFilterInput" value="#{debtorAction.debtorListFilter.firstNameFilter}"
                                     onfocus="var val=this.value; this.value=''; this.value= val;">
                            <a4j:ajax event="keyup" render="allDebtors" execute="@this" oncomplete="#{rich:element('firstNameFilterInput')}.focus()"/>
                        </h:inputText>
                    </f:facet>
                    <h:outputText value="#{debtor.firstName}" />
                </rich:column>

                <rich:column sortBy="#{debtor.middleName}"
                             sortOrder="#{debtorAction.debtorListSort.middleNameOrder}"
                             filterValue="#{debtorAction.debtorListFilter.middleNameFilter}"
                             filterExpression="#{fn:containsIgnoreCase(debtor.middleName,debtorAction.debtorListFilter.middleNameFilter)}"
                        >
                    <f:facet name="header">
                        <a4j:commandLink value="Отчество"
                                         render="allDebtors"
                                         action="#{debtorAction.debtorListSort.sortByMiddleName}"
                                         styleClass="fake-app"
                                />
                        <h:inputText id="middleNameFilterInput" value="#{debtorAction.debtorListFilter.middleNameFilter}"
                                     onfocus="var val=this.value; this.value=''; this.value= val;">
                            <a4j:ajax event="keyup" render="allDebtors" execute="@this" oncomplete="#{rich:element('middleNameFilterInput')}.focus()"/>
                        </h:inputText>
                    </f:facet>
                    <h:outputText value="#{debtor.middleName}" />
                </rich:column>

                <rich:column sortBy="#{debtor.birthday}"
                             sortOrder="#{debtorAction.debtorListSort.birthdayOrder}"
                        >
                    <f:facet name="header">
                        <a4j:commandLink value="День рождения"
                                         render="allDebtors"
                                         action="#{debtorAction.debtorListSort.sortByBirthday}"
                                         styleClass="fake-app"
                                />
                    </f:facet>
                    <h:outputText value="#{debtor.birthday}" />
                </rich:column>

                <rich:column>
                    <div>
                        <rich:panel styleClass="fake-app">
                            <a4j:commandButton value=" "
                                               action="#{debtorAction.setDebtorModel(debtor)}"
                                               oncomplete="#{rich:component('popupAddDebtor')}.show()"
                                               render="addNewDebtorPanel,addDebtorHeader"
                                               styleClass="edit-button" />
                            <rich:tooltip >
                                Редактирование информации о занимателе
                            </rich:tooltip>
                        </rich:panel>
                    </div>
                </rich:column>

                <f:facet name="footer">
                    <rich:dataScroller page="#{debtorAction.page}" />
                    <a4j:commandLink value="все" action="#{debtorAction.setRows(9999)}" render="allDebtors"/>
                </f:facet>
            </rich:dataTable>
        </h:form>

        <ui:include src="popup/addNewDebtor.xhtml">
            <ui:param name="headerValue" value="Добавление нового занимателя"/>
            <ui:param name="headerUpdateValue" value="Редактирование информации о занимателе"/>
            <ui:param name="debtorModel" value="#{debtorAction.debtorModel}"/>
            <ui:param name="rerenderList" value="allDebtors"/>
        </ui:include>
    </ui:define>
</ui:composition>

</html>
